package fun.diaoer.config.security;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;

import fun.diaoer.common.Contants;
import fun.diaoer.common.JsonResult;
import lombok.extern.slf4j.Slf4j;


@Slf4j
@Component
public class DiaoerAccessDeniedHandler implements AccessDeniedHandler {

	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response,AccessDeniedException accessDeniedException) throws IOException, ServletException {
		log.error("无权限访问");
		JsonResult<String> jr=new JsonResult<>();
		jr.setCode(401);
		jr.setStatus(false);
		Contants.buildLoginResponse(request, response);
		jr.setMsg("无权限访问");
		response.getWriter().write(JSON.toJSONString(jr));
	}

}
